/**
 * @file mb_slave.h
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2020-08-25
 * 
 * @copyright Copyright (c) 2020
 * 
 */

#ifndef __MB_SLAVE_H__
#define __MB_SLAVE_H__

#include "3rd/libmodbus/modbus.h"

/* MACRO */
#define MODBUS_POLL_ERROR_RECV (-1)
#define MODBUS_POLL_ERROR_SND (-2)
#define MODBUS_POLL_OK (0)

typedef enum
{
    MB_COIL_GEN_0 = 40,  //
    MB_COIL_GEN_1,
    MB_COIL_GEN_2,
    MB_COIL_GEN_3,
    MB_COIL_GEN_4,
    MB_COIL_GEN_5,
    MB_COIL_GEN_6,
    MB_COIL_GEN_7,
    MB_COIL_GEN_8,
    MB_COIL_GEN_9,
    MB_COIL_GEN_10,
    MB_COIL_GEN_11,
    MB_COIL_GEN_12,
    MB_COIL_GEN_13,
    MB_COIL_GEN_14,
    MB_COIL_GEN_15,
    MB_COIL_GEN_16,
    MB_COIL_GEN_17,
    MB_COIL_GEN_18,
    MB_COIL_GEN_19,
    MB_COIL_GEN_20,
    MB_COIL_GEN_21,
    MB_COIL_GEN_22,
    MB_COIL_GEN_23,
    MB_COIL_GEN_24,
    MB_COIL_GEN_25,
    MB_COIL_GEN_26,
    MB_COIL_GEN_27,
    MB_COIL_GEN_28,
    MB_COIL_GEN_29,
    MB_COIL_GEN_30,
    MB_COIL_GEN_31,
    MB_COIL_GEN_32,
    MB_COIL_GEN_33,
    MB_COIL_GEN_34,
    MB_COIL_GEN_35,
    MB_COIL_GEN_36,
    MB_COIL_GEN_37,
    MB_COIL_GEN_38,
    MB_COIL_GEN_39,
    MB_COIL_GEN_40,
    MB_COIL_GEN_41,
    MB_COIL_GEN_42,
    MB_COIL_GEN_43,
    MB_COIL_GEN_44,
    MB_COIL_GEN_45,
    MB_COIL_GEN_46,
    MB_COIL_GEN_47,
    MB_COIL_GEN_48,
    MB_COIL_GEN_49,
    MB_COIL_GEN_50,
    MB_COIL_GEN_51,
    MB_COIL_GEN_52,
    MB_COIL_GEN_53,
    MB_COIL_GEN_54,
    MB_COIL_GEN_55,
    MB_COIL_GEN_56,
    MB_COIL_GEN_57,
    MB_COIL_GEN_58,
    MB_COIL_GEN_59,
    MB_COIL_GEN_60,
    MB_COIL_GEN_61,
    MB_COIL_GEN_62,
    MB_COIL_GEN_63,
    MB_COIL_GEN_64,
    MB_COIL_GEN_65,
    MB_COIL_GEN_66,
    MB_COIL_GEN_67,
    MB_COIL_GEN_68,
    MB_COIL_GEN_69,
    MB_COIL_GEN_70,
    MB_COIL_GEN_71,
    MB_COIL_GEN_72,
    MB_COIL_GEN_73,
    MB_COIL_GEN_74,
    MB_COIL_GEN_75,
    MB_COIL_GEN_76,
    MB_COIL_GEN_77,
    MB_COIL_GEN_78,
    MB_COIL_GEN_79,
    MB_COIL_GEN_80,
    MB_COIL_GEN_81,
    MB_COIL_GEN_82,
    MB_COIL_GEN_83,
    MB_COIL_GEN_84,
    MB_COIL_GEN_85,
    MB_COIL_GEN_86,
    MB_COIL_GEN_87,
    MB_COIL_GEN_88,
    MB_COIL_GEN_89,
    MB_COIL_GEN_90,
    MB_COIL_GEN_91,
    MB_COIL_GEN_92,
    MB_COIL_GEN_93,
    MB_COIL_GEN_94,
    MB_COIL_GEN_95,
    MB_COIL_GEN_96,
    MB_COIL_GEN_97,
    MB_COIL_GEN_98,
    MB_COIL_GEN_99,
    MB_COIL_GEN_100,
    MB_COIL_GEN_101,
    MB_COIL_GEN_102,
    MB_COIL_GEN_103,
    MB_COIL_GEN_104,
    MB_COIL_GEN_105,
    MB_COIL_GEN_106,
    MB_COIL_GEN_107,
    MB_COIL_GEN_108,
    MB_COIL_GEN_109,
    MB_COIL_GEN_110,
    MB_COIL_GEN_111,
    MB_COIL_GEN_112,
    MB_COIL_GEN_113,
    MB_COIL_GEN_114,
    MB_COIL_GEN_115,
    MB_COIL_GEN_116,
    MB_COIL_GEN_117,
    MB_COIL_GEN_118,
    MB_COIL_GEN_119,
    MB_COIL_GEN_120,
    MB_COIL_GEN_121,
    MB_COIL_GEN_122,
    MB_COIL_GEN_123,
    MB_COIL_GEN_124,
    MB_COIL_GEN_125,
    MB_COIL_GEN_126,
    MB_COIL_GEN_127,
    MB_COIL_GEN_PHY_DO_1,
    MB_COIL_GEN_PHY_DO_2,
    MB_COIL_GEN_PHY_DO_3,
    MB_COIL_GEN_PHY_DO_4,
    MB_COIL_GEN_PHY_DO_5,
    MB_COIL_GEN_PHY_DO_6,
    MB_COIL_GEN_PHY_DO_7,
    MB_COIL_GEN_PHY_DO_8,
    MB_COIL_GEN_PHY_DO_9,
    MB_COIL_GEN_PHY_DO_10,
    MB_COIL_GEN_PHY_DO_11,
    MB_COIL_GEN_PHY_DO_12,
    MB_COIL_GEN_PHY_DO_13,
    MB_COIL_GEN_PHY_DO_14,
    MB_COIL_GEN_PHY_DO_15,
    MB_COIL_GEN_PHY_DO_16,
    MB_COIL_GEN_PHY_TOOL_DO_1,
    MB_COIL_GEN_PHY_TOOL_DO_2,
    MB_COIL_GEN_ALL
} mb_coils_idx_t;

typedef enum
{
    MB_D_INPT_GEN_0 = 8,
    MB_D_INPT_GEN_1,
    MB_D_INPT_GEN_2,
    MB_D_INPT_GEN_3,
    MB_D_INPT_GEN_4,
    MB_D_INPT_GEN_5,
    MB_D_INPT_GEN_6,
    MB_D_INPT_GEN_7,
    MB_D_INPT_GEN_8,
    MB_D_INPT_GEN_9,
    MB_D_INPT_GEN_10,
    MB_D_INPT_GEN_11,
    MB_D_INPT_GEN_12,
    MB_D_INPT_GEN_13,
    MB_D_INPT_GEN_14,
    MB_D_INPT_GEN_15,
    MB_D_INPT_GEN_16,
    MB_D_INPT_GEN_17,
    MB_D_INPT_GEN_18,
    MB_D_INPT_GEN_19,
    MB_D_INPT_GEN_20,
    MB_D_INPT_GEN_21,
    MB_D_INPT_GEN_22,
    MB_D_INPT_GEN_23,
    MB_D_INPT_GEN_24,
    MB_D_INPT_GEN_25,
    MB_D_INPT_GEN_26,
    MB_D_INPT_GEN_27,
    MB_D_INPT_GEN_28,
    MB_D_INPT_GEN_29,
    MB_D_INPT_GEN_30,
    MB_D_INPT_GEN_31,
    MB_D_INPT_GEN_32,
    MB_D_INPT_GEN_33,
    MB_D_INPT_GEN_34,
    MB_D_INPT_GEN_35,
    MB_D_INPT_GEN_36,
    MB_D_INPT_GEN_37,
    MB_D_INPT_GEN_38,
    MB_D_INPT_GEN_39,
    MB_D_INPT_GEN_40,
    MB_D_INPT_GEN_41,
    MB_D_INPT_GEN_42,
    MB_D_INPT_GEN_43,
    MB_D_INPT_GEN_44,
    MB_D_INPT_GEN_45,
    MB_D_INPT_GEN_46,
    MB_D_INPT_GEN_47,
    MB_D_INPT_GEN_48,
    MB_D_INPT_GEN_49,
    MB_D_INPT_GEN_50,
    MB_D_INPT_GEN_51,
    MB_D_INPT_GEN_52,
    MB_D_INPT_GEN_53,
    MB_D_INPT_GEN_54,
    MB_D_INPT_GEN_55,
    MB_D_INPT_GEN_56,
    MB_D_INPT_GEN_57,
    MB_D_INPT_GEN_58,
    MB_D_INPT_GEN_59,
    MB_D_INPT_GEN_60,
    MB_D_INPT_GEN_61,
    MB_D_INPT_GEN_62,
    MB_D_INPT_GEN_63,
    MB_D_INPT_GEN_64,
    MB_D_INPT_GEN_65,
    MB_D_INPT_GEN_66,
    MB_D_INPT_GEN_67,
    MB_D_INPT_GEN_68,
    MB_D_INPT_GEN_69,
    MB_D_INPT_GEN_70,
    MB_D_INPT_GEN_71,
    MB_D_INPT_GEN_72,
    MB_D_INPT_GEN_73,
    MB_D_INPT_GEN_74,
    MB_D_INPT_GEN_75,
    MB_D_INPT_GEN_76,
    MB_D_INPT_GEN_77,
    MB_D_INPT_GEN_78,
    MB_D_INPT_GEN_79,
    MB_D_INPT_GEN_80,
    MB_D_INPT_GEN_81,
    MB_D_INPT_GEN_82,
    MB_D_INPT_GEN_83,
    MB_D_INPT_GEN_84,
    MB_D_INPT_GEN_85,
    MB_D_INPT_GEN_86,
    MB_D_INPT_GEN_87,
    MB_D_INPT_GEN_88,
    MB_D_INPT_GEN_89,
    MB_D_INPT_GEN_90,
    MB_D_INPT_GEN_91,
    MB_D_INPT_GEN_92,
    MB_D_INPT_GEN_93,
    MB_D_INPT_GEN_94,
    MB_D_INPT_GEN_95,
    MB_D_INPT_GEN_96,
    MB_D_INPT_GEN_97,
    MB_D_INPT_GEN_98,
    MB_D_INPT_GEN_99,
    MB_D_INPT_GEN_100,
    MB_D_INPT_GEN_101,
    MB_D_INPT_GEN_102,
    MB_D_INPT_GEN_103,
    MB_D_INPT_GEN_104,
    MB_D_INPT_GEN_105,
    MB_D_INPT_GEN_106,
    MB_D_INPT_GEN_107,
    MB_D_INPT_GEN_108,
    MB_D_INPT_GEN_109,
    MB_D_INPT_GEN_110,
    MB_D_INPT_GEN_111,
    MB_D_INPT_GEN_112,
    MB_D_INPT_GEN_113,
    MB_D_INPT_GEN_114,
    MB_D_INPT_GEN_115,
    MB_D_INPT_GEN_116,
    MB_D_INPT_GEN_117,
    MB_D_INPT_GEN_118,
    MB_D_INPT_GEN_119,
    MB_D_INPT_GEN_120,
    MB_D_INPT_GEN_121,
    MB_D_INPT_GEN_122,
    MB_D_INPT_GEN_123,
    MB_D_INPT_GEN_124,
    MB_D_INPT_GEN_125,
    MB_D_INPT_GEN_126,
    MB_D_INPT_GEN_127,
    MB_INPT_GEN_PHY_DI_1,
    MB_INPT_GEN_PHY_DI_2,
    MB_INPT_GEN_PHY_DI_3,
    MB_INPT_GEN_PHY_DI_4,
    MB_INPT_GEN_PHY_DI_5,
    MB_INPT_GEN_PHY_DI_6,
    MB_INPT_GEN_PHY_DI_7,
    MB_INPT_GEN_PHY_DI_8,
    MB_INPT_GEN_PHY_DI_9,
    MB_INPT_GEN_PHY_DI_10,
    MB_INPT_GEN_PHY_DI_11,
    MB_INPT_GEN_PHY_DI_12,
    MB_INPT_GEN_PHY_DI_13,
    MB_INPT_GEN_PHY_DI_14,
    MB_INPT_GEN_PHY_DI_15,
    MB_INPT_GEN_PHY_DI_16,
    MB_INPT_GEN_PHY_TOOL_DI_1,
    MB_INPT_GEN_PHY_TOOL_DI_2,
    MB_D_INPT_GEN_ALL
} mb_d_inputs_idx_t;

typedef enum
{
    MB_HOLDING_GEN_0 = 100,
    MB_HOLDING_GEN_1,
    MB_HOLDING_GEN_2,
    MB_HOLDING_GEN_3,
    MB_HOLDING_GEN_4,
    MB_HOLDING_GEN_5,
    MB_HOLDING_GEN_6,
    MB_HOLDING_GEN_7,
    MB_HOLDING_GEN_8,
    MB_HOLDING_GEN_9,
    MB_HOLDING_GEN_10,
    MB_HOLDING_GEN_11,
    MB_HOLDING_GEN_12,
    MB_HOLDING_GEN_13,
    MB_HOLDING_GEN_14,
    MB_HOLDING_GEN_15,
    MB_HOLDING_GEN_SIGNED_0,
    MB_HOLDING_GEN_SIGNED_1,
    MB_HOLDING_GEN_SIGNED_2,
    MB_HOLDING_GEN_SIGNED_3,
    MB_HOLDING_GEN_SIGNED_4,
    MB_HOLDING_GEN_SIGNED_5,
    MB_HOLDING_GEN_SIGNED_6,
    MB_HOLDING_GEN_SIGNED_7,
    MB_HOLDING_GEN_SIGNED_8,
    MB_HOLDING_GEN_SIGNED_9,
    MB_HOLDING_GEN_SIGNED_10,
    MB_HOLDING_GEN_SIGNED_11,
    MB_HOLDING_GEN_SIGNED_12,
    MB_HOLDING_GEN_SIGNED_13,
    MB_HOLDING_GEN_SIGNED_14,
    MB_HOLDING_GEN_SIGNED_15,
    MB_HOLDING_FLOAT_0_H,
    MB_HOLDING_FLOAT_0_L,
    MB_HOLDING_FLOAT_1_H,
    MB_HOLDING_FLOAT_1_L,
    MB_HOLDING_FLOAT_2_H,
    MB_HOLDING_FLOAT_2_L,
    MB_HOLDING_FLOAT_3_H,
    MB_HOLDING_FLOAT_3_L,
    MB_HOLDING_FLOAT_4_H,
    MB_HOLDING_FLOAT_4_L,
    MB_HOLDING_FLOAT_5_H,
    MB_HOLDING_FLOAT_5_L,
    MB_HOLDING_FLOAT_6_H,
    MB_HOLDING_FLOAT_6_L,
    MB_HOLDING_FLOAT_7_H,
    MB_HOLDING_FLOAT_7_L,
    MB_HOLDING_FLOAT_8_H,
    MB_HOLDING_FLOAT_8_L,
    MB_HOLDING_FLOAT_9_H,
    MB_HOLDING_FLOAT_9_L,
    MB_HOLDING_FLOAT_10_H,
    MB_HOLDING_FLOAT_10_L,
    MB_HOLDING_FLOAT_11_H,
    MB_HOLDING_FLOAT_11_L,
    MB_HOLDING_FLOAT_12_H,
    MB_HOLDING_FLOAT_12_L,
    MB_HOLDING_FLOAT_13_H,
    MB_HOLDING_FLOAT_13_L,
    MB_HOLDING_FLOAT_14_H,
    MB_HOLDING_FLOAT_14_L,
    MB_HOLDING_FLOAT_15_H,
    MB_HOLDING_FLOAT_15_L,
    MB_HOLDING_FLOAT_16_H,
    MB_HOLDING_FLOAT_16_L,
    MB_HOLDING_FLOAT_17_H,
    MB_HOLDING_FLOAT_17_L,
    MB_HOLDING_FLOAT_18_H,
    MB_HOLDING_FLOAT_18_L,
    MB_HOLDING_FLOAT_19_H,
    MB_HOLDING_FLOAT_19_L,
    MB_HOLDING_FLOAT_20_H,
    MB_HOLDING_FLOAT_20_L,
    MB_HOLDING_FLOAT_21_H,
    MB_HOLDING_FLOAT_21_L,
    MB_HOLDING_FLOAT_22_H,
    MB_HOLDING_FLOAT_22_L,
    MB_HOLDING_FLOAT_23_H,
    MB_HOLDING_FLOAT_23_L,
    MB_HOLDING_FLOAT_24_H,
    MB_HOLDING_FLOAT_24_L,
    MB_HOLDING_FLOAT_25_H,
    MB_HOLDING_FLOAT_25_L,
    MB_HOLDING_FLOAT_26_H,
    MB_HOLDING_FLOAT_26_L,
    MB_HOLDING_FLOAT_27_H,
    MB_HOLDING_FLOAT_27_L,
    MB_HOLDING_FLOAT_28_H,
    MB_HOLDING_FLOAT_28_L,
    MB_HOLDING_FLOAT_29_H,
    MB_HOLDING_FLOAT_29_L,
    MB_HOLDING_FLOAT_30_H,
    MB_HOLDING_FLOAT_30_L,
    MB_HOLDING_FLOAT_31_H,
    MB_HOLDING_FLOAT_31_L,
    MB_HOLDING_PHY_AO_1,
    MB_HOLDING_PHY_AO_2,
    MB_HOLDING_ALL
} mb_holding_reg_idx_t;

typedef enum
{
    MB_IN_REG_GEN_0 = 96,
    MB_IN_REG_GEN_1,
    MB_IN_REG_GEN_2,
    MB_IN_REG_GEN_3,
    MB_IN_REG_GEN_4,
    MB_IN_REG_GEN_5,
    MB_IN_REG_GEN_6,
    MB_IN_REG_GEN_7,
    MB_IN_REG_GEN_8,
    MB_IN_REG_GEN_9,
    MB_IN_REG_GEN_10,
    MB_IN_REG_GEN_11,
    MB_IN_REG_GEN_12,
    MB_IN_REG_GEN_13,
    MB_IN_REG_GEN_14,
    MB_IN_REG_GEN_15,
    MB_IN_REG_GEN_SIGNED_0,
    MB_IN_REG_GEN_SIGNED_1,
    MB_IN_REG_GEN_SIGNED_2,
    MB_IN_REG_GEN_SIGNED_3,
    MB_IN_REG_GEN_SIGNED_4,
    MB_IN_REG_GEN_SIGNED_5,
    MB_IN_REG_GEN_SIGNED_6,
    MB_IN_REG_GEN_SIGNED_7,
    MB_IN_REG_GEN_SIGNED_8,
    MB_IN_REG_GEN_SIGNED_9,
    MB_IN_REG_GEN_SIGNED_10,
    MB_IN_REG_GEN_SIGNED_11,
    MB_IN_REG_GEN_SIGNED_12,
    MB_IN_REG_GEN_SIGNED_13,
    MB_IN_REG_GEN_SIGNED_14,
    MB_IN_REG_GEN_SIGNED_15,
    MB_IN_REG_FLOAT_0_H,
    MB_IN_REG_FLOAT_0_L,
    MB_IN_REG_FLOAT_1_H,
    MB_IN_REG_FLOAT_1_L,
    MB_IN_REG_FLOAT_2_H,
    MB_IN_REG_FLOAT_2_L,
    MB_IN_REG_FLOAT_3_H,
    MB_IN_REG_FLOAT_3_L,
    MB_IN_REG_FLOAT_4_H,
    MB_IN_REG_FLOAT_4_L,
    MB_IN_REG_FLOAT_5_H,
    MB_IN_REG_FLOAT_5_L,
    MB_IN_REG_FLOAT_6_H,
    MB_IN_REG_FLOAT_6_L,
    MB_IN_REG_FLOAT_7_H,
    MB_IN_REG_FLOAT_7_L,
    MB_IN_REG_FLOAT_8_H,
    MB_IN_REG_FLOAT_8_L,
    MB_IN_REG_FLOAT_9_H,
    MB_IN_REG_FLOAT_9_L,
    MB_IN_REG_FLOAT_10_H,
    MB_IN_REG_FLOAT_10_L,
    MB_IN_REG_FLOAT_11_H,
    MB_IN_REG_FLOAT_11_L,
    MB_IN_REG_FLOAT_12_H,
    MB_IN_REG_FLOAT_12_L,
    MB_IN_REG_FLOAT_13_H,
    MB_IN_REG_FLOAT_13_L,
    MB_IN_REG_FLOAT_14_H,
    MB_IN_REG_FLOAT_14_L,
    MB_IN_REG_FLOAT_15_H,
    MB_IN_REG_FLOAT_15_L,
    MB_IN_REG_FLOAT_16_H,
    MB_IN_REG_FLOAT_16_L,
    MB_IN_REG_FLOAT_17_H,
    MB_IN_REG_FLOAT_17_L,
    MB_IN_REG_FLOAT_18_H,
    MB_IN_REG_FLOAT_18_L,
    MB_IN_REG_FLOAT_19_H,
    MB_IN_REG_FLOAT_19_L,
    MB_IN_REG_FLOAT_20_H,
    MB_IN_REG_FLOAT_20_L,
    MB_IN_REG_FLOAT_21_H,
    MB_IN_REG_FLOAT_21_L,
    MB_IN_REG_FLOAT_22_H,
    MB_IN_REG_FLOAT_22_L,
    MB_IN_REG_FLOAT_23_H,
    MB_IN_REG_FLOAT_23_L,
    MB_IN_REG_FLOAT_24_H,
    MB_IN_REG_FLOAT_24_L,
    MB_IN_REG_FLOAT_25_H,
    MB_IN_REG_FLOAT_25_L,
    MB_IN_REG_FLOAT_26_H,
    MB_IN_REG_FLOAT_26_L,
    MB_IN_REG_FLOAT_27_H,
    MB_IN_REG_FLOAT_27_L,
    MB_IN_REG_FLOAT_28_H,
    MB_IN_REG_FLOAT_28_L,
    MB_IN_REG_FLOAT_29_H,
    MB_IN_REG_FLOAT_29_L,
    MB_IN_REG_FLOAT_30_H,
    MB_IN_REG_FLOAT_30_L,
    MB_IN_REG_FLOAT_31_H,
    MB_IN_REG_FLOAT_31_L,
    MB_IN_CAB_PHY_AI_1,
    MB_IN_CAB_PHY_AI_2,
    MB_IN_TOOL_PHY_AI_1,
    MB_IN_TOOL_PHY_AI_2
} mb_input_reg_idx_t;

typedef enum
{

    MB_IN_REG_SERVO_VER_1_H = 300,
    MB_IN_REG_SERVO_VER_1_L,
    // MB_IN_REG_SERVO_VER_2_H,
    // MB_IN_REG_SERVO_VER_2_L,
    // MB_IN_REG_SERVO_VER_3_H,
    // MB_IN_REG_SERVO_VER_3_L,
    // MB_IN_REG_SERVO_VER_4_H,
    // MB_IN_REG_SERVO_VER_4_L,
    // MB_IN_REG_SERVO_VER_5_H,
    // MB_IN_REG_SERVO_VER_5_L,
    // MB_IN_REG_SERVO_VER_6_H,
    // MB_IN_REG_SERVO_VER_6_L,

    MB_IN_REG_ROBOT_SN_1_H,
    MB_IN_REG_ROBOT_SN_1_L,
    // MB_IN_REG_JNT_SN_2_H,
    // MB_IN_REG_JNT_SN_2_L,
    // MB_IN_REG_JNT_SN_3_H,
    // MB_IN_REG_JNT_SN_3_L,
    // MB_IN_REG_JNT_SN_4_H,
    // MB_IN_REG_JNT_SN_4_L,
    // MB_IN_REG_JNT_SN_5_H,
    // MB_IN_REG_JNT_SN_5_L,
    // MB_IN_REG_JNT_SN_6_H,
    // MB_IN_REG_JNT_SN_6_L,

    MB_IN_REG_JNT_PWR_1_H,
    MB_IN_REG_JNT_PWR_1_L,
    MB_IN_REG_JNT_PWR_2_H,
    MB_IN_REG_JNT_PWR_2_L,
    MB_IN_REG_JNT_PWR_3_H,
    MB_IN_REG_JNT_PWR_3_L,
    MB_IN_REG_JNT_PWR_4_H,
    MB_IN_REG_JNT_PWR_4_L,
    MB_IN_REG_JNT_PWR_5_H,
    MB_IN_REG_JNT_PWR_5_L,
    MB_IN_REG_JNT_PWR_6_H,
    MB_IN_REG_JNT_PWR_6_L,

    MB_IN_REG_JNT_TMP_1_H,
    MB_IN_REG_JNT_TMP_1_L,
    MB_IN_REG_JNT_TMP_2_H,
    MB_IN_REG_JNT_TMP_2_L,
    MB_IN_REG_JNT_TMP_3_H,
    MB_IN_REG_JNT_TMP_3_L,
    MB_IN_REG_JNT_TMP_4_H,
    MB_IN_REG_JNT_TMP_4_L,
    MB_IN_REG_JNT_TMP_5_H,
    MB_IN_REG_JNT_TMP_5_L,
    MB_IN_REG_JNT_TMP_6_H,
    MB_IN_REG_JNT_TMP_6_L,

    MB_IN_REG_JNT_ERR_CODE_1_H,
    MB_IN_REG_JNT_ERR_CODE_1_L,
    MB_IN_REG_JNT_ERR_CODE_2_H,
    MB_IN_REG_JNT_ERR_CODE_2_L,
    MB_IN_REG_JNT_ERR_CODE_3_H,
    MB_IN_REG_JNT_ERR_CODE_3_L,
    MB_IN_REG_JNT_ERR_CODE_4_H,
    MB_IN_REG_JNT_ERR_CODE_4_L,
    MB_IN_REG_JNT_ERR_CODE_5_H,
    MB_IN_REG_JNT_ERR_CODE_5_L,
    MB_IN_REG_JNT_ERR_CODE_6_H,
    MB_IN_REG_JNT_ERR_CODE_6_L,

    MB_IN_REG_JNT_ERR_STS_1,
    MB_IN_REG_JNT_ERR_STS_2,
    MB_IN_REG_JNT_ERR_STS_3,
    MB_IN_REG_JNT_ERR_STS_4,
    MB_IN_REG_JNT_ERR_STS_5,
    MB_IN_REG_JNT_ERR_STS_6,

    MB_IN_REG_JNT_EN_STS_1,
    MB_IN_REG_JNT_EN_STS_2,
    MB_IN_REG_JNT_EN_STS_3,
    MB_IN_REG_JNT_EN_STS_4,
    MB_IN_REG_JNT_EN_STS_5,
    MB_IN_REG_JNT_EN_STS_6,
    MB_IN_REG_JNT_CLSN_STS_1,
    MB_IN_REG_JNT_CLSN_STS_2,
    MB_IN_REG_JNT_CLSN_STS_3,
    MB_IN_REG_JNT_CLSN_STS_4,
    MB_IN_REG_JNT_CLSN_STS_5,
    MB_IN_REG_JNT_CLSN_STS_6,
    MB_IN_REG_JNT_CRNT_1_H,  //电流
    MB_IN_REG_JNT_CRNT_1_L,
    MB_IN_REG_JNT_CRNT_2_H,
    MB_IN_REG_JNT_CRNT_2_L,
    MB_IN_REG_JNT_CRNT_3_H,
    MB_IN_REG_JNT_CRNT_3_L,
    MB_IN_REG_JNT_CRNT_4_H,
    MB_IN_REG_JNT_CRNT_4_L,
    MB_IN_REG_JNT_CRNT_5_H,
    MB_IN_REG_JNT_CRNT_5_L,
    MB_IN_REG_JNT_CRNT_6_H,
    MB_IN_REG_JNT_CRNT_6_L,

    MB_IN_REG_ACT_TORQUE_1_H,
    MB_IN_REG_ACT_TORQUE_1_L,
    MB_IN_REG_ACT_TORQUE_2_H,
    MB_IN_REG_ACT_TORQUE_2_L,
    MB_IN_REG_ACT_TORQUE_3_H,
    MB_IN_REG_ACT_TORQUE_3_L,
    MB_IN_REG_ACT_TORQUE_4_H,
    MB_IN_REG_ACT_TORQUE_4_L,
    MB_IN_REG_ACT_TORQUE_5_H,
    MB_IN_REG_ACT_TORQUE_5_L,
    MB_IN_REG_ACT_TORQUE_6_H,
    MB_IN_REG_ACT_TORQUE_6_L,

    MB_IN_REG_JNT_ANGL_1_H,
    MB_IN_REG_JNT_ANGL_1_L,
    MB_IN_REG_JNT_ANGL_2_H,
    MB_IN_REG_JNT_ANGL_2_L,
    MB_IN_REG_JNT_ANGL_3_H,
    MB_IN_REG_JNT_ANGL_3_L,
    MB_IN_REG_JNT_ANGL_4_H,
    MB_IN_REG_JNT_ANGL_4_L,
    MB_IN_REG_JNT_ANGL_5_H,
    MB_IN_REG_JNT_ANGL_5_L,
    MB_IN_REG_JNT_ANGL_6_H,
    MB_IN_REG_JNT_ANGL_6_L,

    MB_IN_REG_JNT_SPD_1_H,
    MB_IN_REG_JNT_SPD_1_L,
    MB_IN_REG_JNT_SPD_2_H,
    MB_IN_REG_JNT_SPD_2_L,
    MB_IN_REG_JNT_SPD_3_H,
    MB_IN_REG_JNT_SPD_3_L,
    MB_IN_REG_JNT_SPD_4_H,
    MB_IN_REG_JNT_SPD_4_L,
    MB_IN_REG_JNT_SPD_5_H,
    MB_IN_REG_JNT_SPD_5_L,
    MB_IN_REG_JNT_SPD_6_H,
    MB_IN_REG_JNT_SPD_6_L,

    MB_IN_REG_TCP_POS_X_H,
    MB_IN_REG_TCP_POS_X_L,
    MB_IN_REG_TCP_POS_Y_H,
    MB_IN_REG_TCP_POS_Y_L,
    MB_IN_REG_TCP_POS_Z_H,
    MB_IN_REG_TCP_POS_Z_L,
    MB_IN_REG_TCP_POS_RX_H,
    MB_IN_REG_TCP_POS_RX_L,
    MB_IN_REG_TCP_POS_RY_H,
    MB_IN_REG_TCP_POS_RY_L,
    MB_IN_REG_TCP_POS_RZ_H,
    MB_IN_REG_TCP_POS_RZ_L,

    MB_IN_REG_TCP_SPD_X_H,
    MB_IN_REG_TCP_SPD_X_L,
    MB_IN_REG_TCP_SPD_Y_H,
    MB_IN_REG_TCP_SPD_Y_L,
    MB_IN_REG_TCP_SPD_Z_H,
    MB_IN_REG_TCP_SPD_Z_L,
    MB_IN_REG_TCP_SPD_RX_H,
    MB_IN_REG_TCP_SPD_RX_L,
    MB_IN_REG_TCP_SPD_RY_H,
    MB_IN_REG_TCP_SPD_RY_L,
    MB_IN_REG_TCP_SPD_RZ_H,
    MB_IN_REG_TCP_SPD_RZ_L,

    MB_IN_REG_TCP_CUR_OFFSET_X_H,
    MB_IN_REG_TCP_CUR_OFFSET_X_L,
    MB_IN_REG_TCP_CUR_OFFSET_Y_H,
    MB_IN_REG_TCP_CUR_OFFSET_Y_L,
    MB_IN_REG_TCP_CUR_OFFSET_Z_H,
    MB_IN_REG_TCP_CUR_OFFSET_Z_L,
    MB_IN_REG_TCP_CUR_OFFSET_RX_H,
    MB_IN_REG_TCP_CUR_OFFSET_RX_L,
    MB_IN_REG_TCP_CUR_OFFSET_RY_H,
    MB_IN_REG_TCP_CUR_OFFSET_RY_L,
    MB_IN_REG_TCP_CUR_OFFSET_RZ_H,
    MB_IN_REG_TCP_CUR_OFFSET_RZ_L,

    MB_IN_REG_BASE_OFFSET_X_H,
    MB_IN_REG_BASE_OFFSET_X_L,
    MB_IN_REG_BASE_OFFSET_Y_H,
    MB_IN_REG_BASE_OFFSET_Y_L,
    MB_IN_REG_BASE_OFFSET_Z_H,
    MB_IN_REG_BASE_OFFSET_Z_L,
    MB_IN_REG_BASE_OFFSET_RX_H,
    MB_IN_REG_BASE_OFFSET_RX_L,
    MB_IN_REG_BASE_OFFSET_RY_H,
    MB_IN_REG_BASE_OFFSET_RY_L,
    MB_IN_REG_BASE_OFFSET_RZ_H,
    MB_IN_REG_BASE_OFFSET_RZ_L,

    MB_IN_REG_PROTECTIVE_STOP,
    MB_IN_REG_EMERGENCY_STOP,
    MB_IN_REG_POWER_ON,
    MB_IN_REG_ENABLE,
    MB_IN_REG_ON_SOFT_LIMIT,
    MB_IN_REG_INPOS,
    MB_IN_REG_MOTION_MODE,
    MB_IN_REG_PERCENTAGE_MODE_LEVEL,

    MB_IN_REG_RAPID_SCALE_H,
    MB_IN_REG_RAPID_SCALE_L,
    MB_IN_REG_MOTION_ERRCODE_H,
    MB_IN_REG_MOTION_ERRCODE_L,
    //CAB  data
    MB_IN_REG_CAB_TEMPERATURE_H,
    MB_IN_REG_CAB_TEMPERATURE_L,
    MB_IN_REG_ROBOT_AVERAGEPOWER_H,
    MB_IN_REG_ROBOT_AVERAGEPOWER_L,
    MB_IN_REG_ROBOT_AVERAGECURRENT_H,
    MB_IN_REG_ROBOT_AVERAGECURRENT_L,
    // uhi_data
    MB_IN_REG_UHI_PULES_H,
    MB_IN_REG_UHI_PULES_L,
    MB_IN_REG_UHI_SPEED_H,
    MB_IN_REG_UHI_SPEED_L,
    MB_IN_REG_UHI_DIR,
    //uhi_origin_data
    MB_IN_REG_UHI_ORIGIN_PULES_H,
    MB_IN_REG_UHI_ORIGIN_PULES_L,
    //error triggerred
    MB_IN_REG_ERROR_TRIGGERED,

    //square speed of TCP in the x, y, and z directions
    MB_IN_REG_TCP_SPD_H,
    MB_IN_REG_TCP_SPD_L,

    //checksum
    MB_IN_REG_CHECKSUM_H,
    MB_IN_REG_CHECKSUM_L,

    // tcp angular speed
    MB_IN_REG_TCP_ANG_H,
    MB_IN_REG_TCP_ANG_L,

    MB_IN_REG_ALL = 555
} mb_input_reg_robot_state_index_t;

#define MB_SRV_DISCRETE_INPUT_START_ADDRESS (MB_D_INPT_GEN_0)
#define MB_SRV_DISCRETE_INPUT_LENGTH (MB_D_INPT_GEN_ALL - MB_D_INPT_GEN_0)

#define MB_SRV_COILS_START_ADDRESS (MB_COIL_GEN_0)
#define MB_SRV_COILS_LENGTH (MB_COIL_GEN_ALL - MB_COIL_GEN_0)

#define MB_SRV_INPUT_REGISTER_START_ADDRESS (MB_IN_REG_GEN_0)  //
#define MB_SRV_INPUT_REGISTER_LENGTH ((uint32_t)MB_IN_REG_ALL - (uint32_t)MB_IN_REG_GEN_0)

#define MB_SRV_HOLDING_REGISTER_START_ADDRESS (MB_HOLDING_GEN_0)            //
#define MB_SRV_HOLDING_REGISTER_LENGTH (MB_HOLDING_ALL - MB_HOLDING_GEN_0)  //

typedef struct mb_rtu_comm_para_s
{
    int baudrate;
    int byte_len;
    int parity;
    int stop_bit_len;
} mb_rtu_comm_para_t;

typedef struct mb_tcp_comm_para_s
{
    char ip_addr[16];
    int port;
} mb_tcp_comm_para_t;

typedef struct mb_slave_comm_para_s
{
    char deviceName[128];
    int mb_comm_type;  //0-rtu 1-tcp
    int slave_id;
    mb_rtu_comm_para_t rtu_comm_para;
    mb_tcp_comm_para_t tcp_comm_para;
    int indication_timeout_sec;
    int indication_timeout_usec;
    int response_timeout_sec;
    int response_timeout_usec;
} mb_slave_comm_para_t;

typedef struct mb_slave_s
{
    modbus_mapping_t* slave_reg_mapping;
    mb_slave_comm_para_t slave_comm_para;
} mb_slave_t;

//extern int zuc_cab_type;
extern void mb_slave_ServerThread();

#endif
